rm(list = ls())

library(tidyverse)
library(janitor)

dat <- readRDS('data/figA4.rds')  

## Plot 

corr <- cor(dat$zip_2011_foreign, dat$citizen_foreign_county, use = 'complete.obs')

p1 <- ggplot(dat, aes(x = zip_2011_foreign, y = citizen_foreign_county, size = total)) +
    geom_point(fill = 'white', shape = 21) +
    geom_smooth(method = 'lm', se = F, col = 'grey20', size = .8, linetype = 'dashed') +
    theme_minimal() +
    scale_color_manual(values = c('red', 'blue')) + 
    labs(x = 'Share foreign citizens\n(zip-code level)',
         y = 'Share foreign citizens\n(county level)') + 
    scale_y_continuous(labels = scales::percent) + 
    scale_x_continuous(labels = scales::percent)  +   
    annotate("text", x = 0.94, y = .65, 
             label = paste("r = ", round(corr, 2)), 
             hjust = "right", vjust = "top",
             size = 6) +
    scale_size_continuous(range = c(.5, 10), name = 'Population\n(zip-code)')  # Adjusts the size range

p1


